do "...\First.do"

********************************************************************************
* In this file, I find all individuals working in clinics and keep people with a
* degree in medicine.
********************************************************************************


* Find PCPs medical school
clear
use  "$raw\registration.dta" 
drop if missing(pnr)

keep pnr SCHOOL_NAME YEAR
rename SCHOOL_NAME school 
rename YEAR year_doctor

save "$work\registration.dta", replace


** Finds doctors' pnrs and merge with information about highest achived education and 
** Information about medical school
clear 
use "$raw\T_yder_1.dta" // Doctors in private practises (including PCPs) in years 1995-2014

append using "$raw\t_yder_person.dta" // Doctors in private practises (including PCPs) in years 2014-2018

keep pnr
duplicates drop
drop if missing(pnr)

merge 1:m pnr using "$raw\Children3.dta" // Adds information about education
drop if _merge==2
drop _merge
sort pnr year


format hfaudd %4.0f
drop if missing(hfaudd)
g doctor=(hfaudd==7170) // master in medicine

keep pnr doctor
keep if doctor==1
duplicates drop 

** Find medical school from registrations 
merge 1:1 pnr using "$work\registration.dta"
drop if _merge==2
drop _merge

egen help=group(school)
tab school help, m
g gp_school=1 if help==3
replace gp_school=2 if help==2
replace gp_school=3 if help==4
replace gp_school=4 if gp_school==.

label define gp_school 1 "KU" 2 "AU" 3 "SDU" 4 "Other"
label values gp_school gp_school


save "$work\doctor_udd.dta", replace




